package com.xuetang9.t9.hotel.mapper;


import com.xuetang9.t9.hotel.beans.RoomInfo;
import com.xuetang9.t9.hotel.mapper.condition.ICondition;
import com.xuetang9.t9.hotel.mapper.sql.impl.RoomInfoMapperSql;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Pang
 */
@Repository
public interface IRoomInfoMapper {


    /**
     * 根据复合条件查询
     * @param roomInfoCondition
     * @return
     */
    @SelectProvider(type = RoomInfoMapperSql.class, method = "selectByAll")
    @Results(id = "roomResult",value = {
            @Result(id = true,column = "room_id", property = "roomId"),
            @Result(column = "type_id", property = "roomType", one = @One(select = "com.xuetang9.t9.hotel.mapper.IRoomTypeMapper.selectById",fetchType = FetchType.EAGER)),
            @Result(column = "state_id", property = "roomState", one = @One(select = "com.xuetang9.t9.hotel.mapper.IRoomStateMapper.selectById",fetchType = FetchType.EAGER)),
            @Result(column = "floor_id", property = "floor", one = @One(select = "com.xuetang9.t9.hotel.mapper.IFloorMapper.selectById",fetchType = FetchType.EAGER)),
            @Result(column = "room_id", property = "roomPhoto", one = @One(select = "com.xuetang9.t9.hotel.mapper.IRoomPhotoMapper.selectByRoomId",fetchType = FetchType.EAGER))
    })
    List<RoomInfo> selectByAll(@Param("key") ICondition roomInfoCondition);

    /**
     * 根据条件查询数据总量
     * @param roomInfoCondition
     * @return
     */
    @SelectProvider(type = RoomInfoMapperSql.class, method = "selectByCount")
    Long selectByCount(@Param("key") ICondition roomInfoCondition);

    /**
     * 根据房间状态检索
     * @param id
     * @return
     */
    @Select("SELECT * FROM g_roominfo WHERE state_id=#{id}")
    List<RoomInfo> selectByStateId(@Param("id") Integer id);


    /**
     * 根据房间类型检索
     * @param id
     * @return
     */
    @Select("SELECT * FROM g_roominfo WHERE type_id=#{id}")
    List<RoomInfo> selectByTypeId(@Param("id") Integer id);

    /**
     * 根据房间号查询房间
     * @param roomName
     * @return
     */
    @Select("SELECT * FROM g_roominfo WHERE room_num = #{id}")
    RoomInfo selectByRoomName(@Param("id") String roomName);


    /**
     * 根据房间编号查询房间
     * @param roomId
     * @return
     */
    @Select("SELECT * FROM g_roominfo WHERE room_id=#{id}")
    @ResultMap(value = "roomResult")
    RoomInfo selectByRoomId(@Param("id") Integer roomId);


    /**
     * 新增房间
     * @param roomInfo
     * @return
     */
    @Insert("INSERT INTO g_roominfo(room_num,floor_id,type_id,state_id,room_comm) VALUE(#{roomNum},#{floorId},#{typeId},#{stateId},#{roomComm})")
    int insert(RoomInfo roomInfo);


    /**
     * 更新房间
     * @param roomInfo
     * @return
     */
    @Update("UPDATE g_roominfo SET room_num=#{roomNum},floor_id=#{floorId},type_id=#{typeId},state_id=#{stateId},room_comm=#{roomComm} WHERE room_id=#{roomId}")
    int update(RoomInfo roomInfo);


    /**
     * 删除房间
     * @param id
     * @return
     */
    @DeleteProvider(value = RoomInfoMapperSql.class, method = "delete")
    int delete(@Param("key") Integer... id);

    /**
     * 批量修改房间状态
     * @param rooms
     * @param statr
     * @return
     */
    @UpdateProvider(value = RoomInfoMapperSql.class,method = "updateByStatrt")
    int updateByStart(@Param("rooms") List<Integer> rooms,@Param("id") Integer statr);

    /**
     * 根据楼层编号删除房间
     * @param floorId
     * @return
     */
    @Delete("DELETE FROM g_roominfo WHERE floor_id = #{id}")
    int deleteByFloorId(Integer floorId);

    /**
     * 根据楼层查询房间
     * @param id
     * @return
     */
    @Select("SELECT * FROM g_roominfo WHERE floor_id = #{id}")
    List<RoomInfo> selectBtFloorId(Integer id);

}
